package com.qixin.part.controller;
import com.alibaba.fastjson.JSONObject;
import com.qixin.api.bean.ComCarCharge;
import com.qixin.api.bean.ResultPage;
import com.qixin.api.bean.VoPage;
import com.qixin.api.service.ComCarChargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession;
import java.math.BigDecimal;

/**
 * <p>
 *  充电车辆信息 前端控制器
 * </p>
 *
 * @author 张子艺
 * @since 2018-11-16
 */
@Controller
@RequestMapping("/comCarCharge")
public class ComCarChargeController {

    @Autowired
    ComCarChargeService comCarChargeService;
    /**
     * 跳转企业车辆
     * @return
     */
    @RequestMapping("/main.html")
    public String carftl(){
        return "company/PtCar";
    }
    /**
     * 跳转添加企业车辆
     * @return
     */
    @RequestMapping("/add.html")
    public String add(){
        return "company/PtCarAdd";
    }
	/**
	 * 跳转分配企业车辆
	 * @return
	 */
	@RequestMapping("/allotcar.html")
	public String allotcar(Long id , Model model){
		model.addAttribute("relacationId",id);
		return "company/car_join";
	}
	//分车
	@RequestMapping("/allotcar")
	@ResponseBody
	public boolean allotcar(Long relacationId, Long id) {
		Boolean allotcar=comCarChargeService.allotcar(relacationId,id);
		if (allotcar){
			return true;
		}
		return  false;
	}
	//收车
	@RequestMapping("/recoverycar")
	@ResponseBody
	public boolean recoverycar(Long id) {
		Boolean recoverycar=comCarChargeService.recoverycar(id);
		if (recoverycar){
			return true;
		}
		return  false;
	}
    /**
     * 添加车辆
     * @return
     */
    @RequestMapping("/insertPtCar")
    @ResponseBody
    public Boolean insertPtCar(String param){
        ComCarCharge comCarCharge=JSONObject.parseObject(param, ComCarCharge.class);
        comCarCharge.setMoeny(new BigDecimal(0));
        if(comCarChargeService.insert(comCarCharge)){
            return true;
        }else{
            return  false;
        }
    }
    /**
     * 查询车辆
     * @return
     */
    @RequestMapping("/list")
    @ResponseBody
    public ResultPage<ComCarCharge> list(VoPage voPage){
        return comCarChargeService.selectMyPage(voPage);

    }
    /**
     * 分配资金
     * @return
     */
    @RequestMapping("/giveMoeny")
    @ResponseBody
    public boolean giveMoeny(Long id,BigDecimal moeny, HttpSession session){
        return comCarChargeService.giveMoeny(id,moeny,session);

    }
    /**
     * 回收资金
     * @return
     */
    @RequestMapping("/removeMoeny")
    @ResponseBody
    public String removeMoeny(Long id,BigDecimal moeny, HttpSession session){
        return comCarChargeService.removeMoeny(id,moeny,session);

    }
	//查询未分配车辆
	@RequestMapping("/allotlist")
	@ResponseBody
	public ResultPage<ComCarCharge> allotlist(VoPage voPage, HttpSession session) {
		ResultPage<ComCarCharge> resultPage= comCarChargeService.selectnull(voPage,session );
		return  resultPage;
	}
}
